 /*
Jack Morris
11/20/14
Menu
*/
#include <stdio.h>
#inculde <stdlib.h>
#include <stdlib.h>
#include <time.h>


  
void MainMenu()
{
    printf("\n|-------------------------------|\n");/*  this is menu */
    printf("| How cool are you? - J. Morris |\n");/*  this is menu */
    printf("|-------------------------------|\n\n");/*this is menu */
    printf("1. for guess a number\n");/*option 1 */
    printf("2. for craps\n");/*option 2 */
    printf("3. cool\n");/*option 3 */
    printf("4. eh sorda cool\n");/*option 4 */
    printf("5. not cool\n");/*option 5 */
    printf("6. what is this being cool you speak of?\n"); /*option 6 */
    printf("x to quit\n");
}

void GuessANumber()
{
  #define MAX_NUMBER 100

  /* external variable */
  int secret_number;

  /* prototypes */
  void initialize_number_generator(void);
  void choose_new_secret_number(void);
  void read_guesses(void);

  int main(void)
  {
    char command;

    printf("Guess the secret number between 1 and %d.\n\n", MAX_NUMBER);
    initialize_number_generator();
    do {
      choose_new_secret_number();
      printf("A new number has been chosen.\n");
      read_guesses();
      printf("Play again? (Y/N) ");
      scanf(" %c", &command);
      printf("\n");
    } while (command == 'y' || command == 'Y');

    return 0;
  }

  void initialize_number_generator(void)
  {
    srand((unsigned) time(NULL));
  }

  void choose_new_secret_number(void)
  {
    secret_number = rand() % MAX_NUMBER + 1;
  }

  void read_guesses(void)
  {
    int guess, num_guesses = 0;

    for (;;) {
      num_guesses++;
      printf("Enter guess: ");
      scanf("%d", &guess);
      if (guess == secret_number) {
        printf("You won in %d guesses!\n\n", num_guesses);
        return;
      } else if (guess < secret_number)
        printf("Too low; try again.\n");
      else
        printf("Too high; try again.\n");
    }
  }
}

void MenuOutput()
{
  int input;
  input = 0;
  scanf("%d", &input);
  if(input == 'x')
  {
    return;
  }
  else if (input <= 0 || input >= 7) /*for inputs outside of the range  */
  {
    printf("Bruh that input ain't cool.\n");
  }
  else if (input == 1) /*responce 1 */
  {
    GuessANumber();
  }
  else if (input == 2)/*responce 2 */
  {
    CrapsTheGame();
  }
  else if (input == 3)/*responce 3 */
  {
    printf("Cool man, Cool\n");
  }
  else if (input == 4)/*responce 4 */
  {
    printf("Your sorda cool? Well your almost there\n");
  }
  else if (input == 5)/*responce 5 */
  {
    printf("It's ok not everyone can be cool\n");
  }
  else if (input == 6)/*responce 6 */
  {
    printf("Cool is a term used by all the cool kids nowadays\n");
  }
}

void CrapsTheGame()
{
  int roll_dice(void);
  bool play_game(void);

  int main()
  {
     int i, ch,win = 0,lose = 0;
     bool flag;
     srand((unsigned)time(NULL));

     do
     {
         flag = play_game();
         if(flag)
         {
             printf("You win!");
             win++;
         }
         else
         {
             printf("You lose!");
             lose++;
         }

         printf("\n\nPlay again(Y/N)? ");
         scanf("%c", &ch);
         ch = getchar();
         printf("\n");
     }while(ch == 'Y' || ch == 'y');

     printf("\nWins: %d   Losses: %d",win,lose);
     return 0;
  }

  int roll_dice(void)
  {
      return rand()%6 + rand()%6 + 2;
  }

  bool play_game(void)
  {
     int sum = roll_dice();

     printf("You rolled: %d\n", sum);
     if(sum == 7 || sum == 11)
         return 1;
     else if(sum == 2 || sum == 3 || sum == 12)
         return 0;    
     else
     {
         int point = sum;
         printf("Your point is: %d\n", point);
         do
         {
             sum = roll_dice();
             printf("You rolled: %d\n", sum);
             if(sum == 7)
                 return 0;            
         }while(point != sum);
         return 1;
     }                    
  }
}

int main()
{
  MainMenu();
  MenuOutput();
}

